﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CM.BL.BE;
using System.Collections.Generic;
using CM.BL.BC;

namespace WebApp_2
{
    public partial class detail : System.Web.UI.Page
    {
        private RfcConfigParametersBE _objConn;
        private void checkLogin()
        {
            lblErrorMsg.InnerHtml = string.Empty;
            _objConn = (RfcConfigParametersBE)Session["objConn"];
            if (_objConn == null)
            {
                Response.Redirect("Default.aspx");
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            string retval = string.Empty; string po = string.Empty, m = string.Empty;
            this.checkLogin();
            if (!Page.IsPostBack)
            {
                po = Request.QueryString["po"];
                m = Request.QueryString["m"];
                if (string.IsNullOrEmpty(po))
                {
                    Response.Redirect("List.aspx");
                }

                List<PurchaseOrderBE> lstPO = (List<PurchaseOrderBE>)Session["lstPO"];
                if (lstPO == null || lstPO.Count == 0)
                {
                    retval = PurchaseOrderBC.getInstance(Session.SessionID).getItemsForRelease(out lstPO);
                    Session["lstPO"] = lstPO;
                    lblErrorMsg.InnerHtml = retval.Trim();
                }
                PurchaseOrderBE pObj = lstPO.Find(X => X.PO == po);
                if (pObj == null) { Response.Redirect("List.aspx"); }
                lvpo1.DataSource = pObj.Items;
                lvpo1.DataBind();

                lblMoneda.InnerHtml = pObj.Moneda;
                lblTotal.InnerHtml = string.Format("{0:0,0.00}", pObj.TotBruto);
                lblPO.InnerHtml = pObj.PO;
                lblCodProv.InnerHtml = pObj.CodProveedor;
                lblDesProv.InnerHtml = pObj.DescProveedor;
                lblUsuario.InnerHtml = pObj.CodUsuario;
                lblCondPago.InnerHtml = pObj.CondPagoT;
                lblFecha.InnerHtml = pObj.Fecha.Equals(string.Empty) ? pObj.Fecha : (Convert.ToDateTime(pObj.Fecha)).ToShortDateString();
                lblCount.InnerHtml = pObj.Items.Count.ToString();
                lblTipo.InnerHtml = pObj.ClaseDocT;

                btnLib.HRef = string.Format(btnLib.HRef, pObj.PO, pObj.LibCod);
                lblErrorMsg.InnerHtml = m;
            }
        }
    }
}
